<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    // 获取本地时间
    var date = new Date();
    // 获取年份
    var years = date.getFullYear();
    var months = date.getMonth()+1;
    var days = date.getDate();//这是获取日期
    var hours = date.getHours();
    var mins = date.getMinutes();
    var seconds = date.getSeconds();
    // 定义一个星期的数组
    var week = ["星期天","星期一","星期二","星期三",
        "星期四","星期五","星期六"];
    var weekday = date.getDay();//这个是获取索引值
    var weekdays = week[weekday];

    var str = years+"-"+months+"-"+days+" "+hours+":"+mins+":"+seconds+" "+weekdays;
    console.log(str);

    // 将时间转换成字符串
    date = date.toLocaleString();
    console.log(date);
</script>

</body>
</html>